package com.pipi.biyesheji.controller;

import com.pipi.biyesheji.dao.support.PageResult;
import com.pipi.biyesheji.pojo.Review;
import com.pipi.biyesheji.service.ProductService;
import com.pipi.biyesheji.service.ReviewService;
import com.pipi.biyesheji.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 评论模块controller
 * @author pipi
 */
@Controller
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @RequestMapping("/list")
    public String list(Model model, Page page){
        //分页查询
        PageResult<Review> pageResult= reviewService.list(page);
        //总条数
        int totalCount = pageResult.getTotalCount();
        page.setTotal(totalCount);

        model.addAttribute("totals", totalCount);
        model.addAttribute("list", pageResult.getResult());
        return "pinglunpage/pinglun";
    }

    @RequestMapping("/del")
    public String del(Long id){
        reviewService.del(id);
        return "redirect:list";
    }

}
